#include "mainwidget.h"
#include "ui_mainwidget.h"
#include "pixitem.h"
#include<math.h>
MainWidget::MainWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MainWidget)
{
    ui->setupUi(this);

    setWindowTitle("GraphicsView图形视图架构--应用程序测试");

    iAngle=3;//角度
    scalevalues=3;//缩放
    leanvalues=3;//倾斜

    ui->revolveSlider->setRange(0,360);//角度
    ui->revolveSlider->setValue(0);
    ui->scalingSlider->setRange(0,2*scalevalues);//缩放
    ui->scalingSlider->setValue(scalevalues);//设置滑动条得值
    ui->inclineSlider->setRange(0,2*leanvalues);//倾斜
    ui->inclineSlider->setValue(leanvalues);

    //创建场景
    QGraphicsScene *scence=new QGraphicsScene(-200,-200,380,380);


    //创建图元
    QPixmap *pix1=new QPixmap("D:\\job\\qt\\work\\teacher\\day3\\3.png");
    PixItem *item=new PixItem(pix1);
    scence->addItem(item);
    item->setPos(0,0);

    //创建视图（ui界面已经创建好了)
    ui->gV->setScene(scence);
    ui->gV->setMinimumSize(800,600);

    connect(ui->revolveSlider,&QSlider::sliderMoved,this,&MainWidget::rotateFunc);//旋转
    connect(ui->scalingSlider,&QSlider::sliderMoved,this,&MainWidget::scaleFunc);//缩放
    connect(ui->inclineSlider,&QSlider::sliderMoved,this,&MainWidget::leanFunc);//倾斜

}

MainWidget::~MainWidget()
{
    delete ui;
}

void MainWidget::rotateFunc(int val) //旋转
{
    ui->gV->rotate(val);
    iAngle=val;
}

void MainWidget::scaleFunc(int val)//缩放
{
    qreal qs;
    if(val>scalevalues)
    {
        qs=pow(1.1,(val-scalevalues));
    }
    else if(val<scalevalues)
        qs=pow(1/1.1,(scalevalues-val));
    ui->gV->scale(qs,qs);
    scalevalues=val;
}

void MainWidget::leanFunc(int val)//倾斜
{
    ui->gV->shear((val-leanvalues)/2.0,0);
    leanvalues=val;
}

